package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type AppConfig struct {
	Mysql
	Redis
	Qiniuyun
	Jwt
}
type Mysql struct {
	User     string
	Password string
	Host     string
	Port     int
	Database string
}

type Redis struct {
	Password string
	Host     string
	Port     int
	Database int
}
type Qiniuyun struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Url       string
}
type Jwt struct {
	APP_KEY string
}

var AppConf AppConfig

func Init() {
	viper.SetConfigFile("../appconfig/dev.yaml")

	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	} else {
		fmt.Println("动态配置连接成功")
	}
	err = viper.Unmarshal(&AppConf)
	if err != nil {
		panic(err)
	} else {
		fmt.Println(AppConf)
	}
}
